﻿using MediatR;
using System.CJL.API.Application.Command.ProcessCommand;
using System.CJL.Domain;
using System.CJL.Infrstructre.Interface;
using System.Diagnostics;

namespace System.CJL.API.Application.CommandHanlder.ProcessCommandHanler
{
    /// <summary>
    /// 工序修改
    /// </summary>
    public class ProcessUpdateCommandHandler : IRequestHandler<ProcessUpdateCommand,int>
    {
        IProcessRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        public ProcessUpdateCommandHandler(IProcessRepository repository)
        {
            _repository=repository;
        }

        public async Task<int> Handle(ProcessUpdateCommand request, CancellationToken cancellationToken)
        {
            return await  _repository.UpdateAsync(new Domain.Process
            {
                ProcessId=request.ProcessId,
                ProcessNumebring = request.ProcessNumebring,
                ProcessName = request.ProcessName,
                ProcessStatus = request.ProcessStatus,
                ProcessIllustrate = request.ProcessIllustrate,
                ProcessReamrk = request.ProcessReamrk,
                ProcessDate = request.ProcessDate.ToUniversalTime(),
                IsDelete = false,
                AddName = request.AddName,
                AddTime = request.AddTime,
                UpdateName= request.UpdateName,
                UpdateTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
